// deps: Util and Timer
var TimedUtil = {

	fading:             'Util.node.fading',
	collapsed:          'Util.node.collapsed',

	afterClicksRun: function( clicks, callback ) {
		this.current = 0;
		this.max = clicks;
		this.callback = callback;

		this.run = function( t ) {
			var not_done = true;
			if ( this.current++ > this.max ) {
				if ( callback ) {
					callback();
				}
				not_done = false;
			}
			return not_done;
		}
	},

	fadeToggleVisibility: function( element ) {
		try {
			if ( 'hidden' == element.style.visibility ) {
				TimedUtil.fadeInElement( element );
			} else {
				TimedUtil.fadeOutElement( element );
			}
		} catch( a_cold ) {
		}
	},

	fadeInElement: function( element, callback ) {
		if ( !element.style ) return;
		var Fader = function( element, callback ) {
			this.element = element;
			this.opacity = 0;
			element.style.opacity ? element.style.opacity : 0;
			this.inc = 0.01;
			this.callback = callback;

			this.run = function( t ) {
				Util.visible( this.element );
				Util.show( this.element );
				this.opacity += this.inc;
				this.inc *= 2;
				Util.opaque( this.element, this.opacity );
				return this.opacity <= 1;
			};
			this.done = function( tick ) {
				if ( this.callback ) {
					this.callback( this );
				}
			};
		};
		Timer.addTask( new Fader( element, callback ) );
	},

	fadeIn: function( id, callback ) {
		TimedUtil.fadeInElement( Util.id( id ), callback );
	},

	fadeOutElement: function( element, callback ) {
		var Fader = function( element, callback ) {
			this.element = element;
			this.opacity = element.style.opacity ? element.style.opacity : 1;
			this.inc = 0.01;
			this.callback = callback;
			this.run = function( t ) {
				this.opacity -= this.inc;
				this.inc *= 1.5;
				Util.opaque( this.element, this.opacity );
				return this.opacity >= 0;
			};
			this.done = function( tick ) {
				if ( this.callback ) {
					this.callback( this );
				}
				Util.visible( this.element );
				Util.hide( this.element );
			};
		};
		Timer.addTask( new Fader( element, callback ) );
	},

	fadeOut: function( id, callback ) {
		/* TimedUtil.fadeOut( 'search_image', callback ); */
		TimedUtil.fadeOutElement( Util.id( id ), callback );
	},

	noop: function() {}
};
